GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#2835)
by
unknown
06:01
created

$.fn.symphonyPickable   B

Complexity

Conditions 1
Paths 4

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 81
rs 8.8076

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * @package assets
3
 */
4
5
(function($) {
6
	'use strict';
7
8
	/**
9
	 * Pickable allows to show and hide elements based on the value of a select box.
10
	 *
11
	 * Each option is mapped to its associated content by matching the option `value`
12
	 * with the content `id`. If the option value is numeric, Pickable prefices it
13
	 * with `choice`. Only the content of the currently selected option is
14
	 * shown, all other elements associated with the given select box are hidden.
15
	 *
16
	 * If no content element of the given `id` is found, Pickable checks for a
17
	 * `data-request` attribute on the selected option. If a `data-request` URL is set,
18
	 * Pickable tries to fetch the content remotely and expects an content element with
19
	 * no additional markup in return.
20
	 *
21
	 * @name $.symphonyPickable
22
	 * @class
23
	 *
24
	 * @param {Object} options An object containing the element selectors specified below
25
	 * @param {String} [options.content='#contents'] Selector to find the container that wraps all pickable elements
26
	 * @param {String} [options.pickables='.pickable'] Selector used to find pickable elements
27
	 *
28
	 * @example
29
30
			$('.picker').symphonyPickable();
31
	 */
32
	$.fn.symphonyPickable = function(options) {
33
		var objects = $(this),
34
			settings = {
35
				content: '#contents',
36
				pickables: '.pickable'
37
			};
38
39
		$.extend(settings, options);
40
41
	/*-------------------------------------------------------------------------
42
		Events
43
	-------------------------------------------------------------------------*/
44
45
		// Switch content
46
		objects.on('change.pickable', function pick() {
47
			var object = $(this),
48
				choice = object.val(),
49
				relation = object.attr('id') || object.attr('name'),
50
				related = $(settings.pickables + '[data-relation="' + relation + '"]'),
51
				picked, request;
52
53
			// Handle numeric values
54
			if($.isNumeric(choice) === true) {
55
				choice = 'choice' + choice;
56
			}
57
58
			// Hide all choices
59
			object.trigger('pickstart.pickable');
60
			related.hide().find('input, select, textarea').prop('readonly', true);
61
62
			// Selection found
63
			picked = $('#' + choice);
64
			if(picked.length > 0) {
65
				picked.show().find('input, select, textarea').prop('readonly', false).trigger('pick.pickable');
66
				object.trigger('pickstop.pickable');
67
			}
68
69
			// Selection not found
70
			else {
71
				request = object.data('request');
72
73
				// Fetch picked element
74
				if(request) {
75
					$.ajax({
76
						type: 'GET',
77
						url: request,
78
						data: { 'choice': choice },
79
						dataType: 'html',
80
						success: function(remote) {
81
							content.append(remote);
82
							remote.trigger('pick.pickable');
83
							object.trigger('pickstop.pickable');
84
						}
85
					});
86
				}
87
			}
88
		});
89
90
	/*-------------------------------------------------------------------------
91
		Initialisation
92
	-------------------------------------------------------------------------*/
93
94
		var content = $(settings.content);
95
96
		// Set up relationships
97
		objects.each(function init() {
98
			var object = $(this),
99
				relation = object.attr('id') || object.attr('name');
100
101
			object.find('option').each(function() {
102
				$('#' + $(this).val()).attr('data-relation', relation);
103
			});
104
		});
105
106
		// Show picked content
107
		objects.trigger('change.pickable');
108
109
	/*-----------------------------------------------------------------------*/
110
111
		return objects;
112
	};
113
114
})(window.jQuery);
115